//
//  SYSecondMainTableViewCell.m
//  TermOfSectionB
//
//  Created by dlios on 15/12/3.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "SYSecondMainTableViewCell.h"
#import "SYSecondMainCollectionViewCell.h"
#import "SYSecondViewControllerModel.h"

@interface SYSecondMainTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation SYSecondMainTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMainCollectionView];
    }
    return self;
}

// 创建CollectionView
- (void)createMainCollectionView {
    UICollectionViewFlowLayout *flowt = [[UICollectionViewFlowLayout alloc] init];
    flowt.itemSize = CGSizeMake(72, 95);
    flowt.sectionInset = UIEdgeInsetsMake(20, 5, 2, 2);
    
    self.mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 375, 340) collectionViewLayout:flowt];
    self.mainCollectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.mainCollectionView];
    self.mainCollectionView.dataSource = self;
    self.mainCollectionView.delegate = self;
    
    [self.mainCollectionView registerClass:[SYSecondMainCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.mainArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SYSecondMainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    SYSecondViewControllerModel *model = self.mainArray[indexPath.row];
    cell.myLabel.text = model.name;
    [cell.picImage sd_setImageWithURL:[NSURL URLWithString:model.logo]];
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
